//
//  XMLoginPrivacyTipView.m
//  XunMi
//
//  Created by MacBook on 2024/2/21.
//  Copyright © 2024 TieZhu. All rights reserved.
//

#import "XMLoginPrivacyTipView.h"

@interface XMLoginPrivacyTipView ( )<UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UILabel *titleLa;
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet UIButton *leftButton;
@property (weak, nonatomic) IBOutlet UIButton *rightButton;

@property (nonatomic, copy) void(^leftBlock)(void);
@property (nonatomic, copy) void(^rightBlock)(void);
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *leftSpace;

@end

@implementation XMLoginPrivacyTipView

- (void)awakeFromNib {
    [super awakeFromNib];
    kCornerRadius(self, 20, 0, UIColor.clearColor);
}

- (IBAction)leftAct:(UIButton *)sender {
    if (self.leftBlock) {
        self.leftBlock();
    }
}

- (IBAction)rightAct:(UIButton *)sender {
    if (self.rightBlock) {
        self.rightBlock();
    }
}

- (void)setupProtocolAndPrivacy {
    self.leftSpace.constant = 50;
    
    self.titleLa.text = @"请同意隐私条款";
    [self.leftButton setTitle:@"不同意" forState:UIControlStateNormal];
    [self.rightButton setTitle:@"同意" forState:UIControlStateNormal];
    
    NSString *str = @"登录注册需要您阅读并同意我们的《用户协议》和《隐私政策》";
    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:str];
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing = 8;
    paragraphStyle.alignment = NSTextAlignmentCenter;
    [text addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text length])];
    
    [text addAttributes:@{NSForegroundColorAttributeName:kHEX(@"#9A9A9A"), NSFontAttributeName:kUIFont(12)} range:NSMakeRange(0, str.length)];
    [text addAttribute:NSLinkAttributeName value:@"protocol://" range:[str rangeOfString:@"《用户协议》"]];
    [text addAttribute:NSLinkAttributeName value:@"privacy://" range:[str rangeOfString:@"《隐私政策》"]];
    
    self.textView.linkTextAttributes = @{NSForegroundColorAttributeName:kAppMainColor, NSFontAttributeName:kUIFont(12)};
    self.textView.attributedText = text;
    self.textView.delegate = self;
}

- (void)setupVoice {
    self.leftSpace.constant = 50;

    self.titleLa.text = @"是否更改语音签名";
    [self.leftButton setTitle:@"更改" forState:UIControlStateNormal];
    [self.rightButton setTitle:@"关闭" forState:UIControlStateNormal];
    
    NSString *str = @"如需听已录制的语音请到\n【我的】- 个人简介详情里查看";
    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:str];
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing = 8;
    paragraphStyle.alignment = NSTextAlignmentCenter;
    [text addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text length])];
    
    [text addAttributes:@{NSForegroundColorAttributeName:kHEX(@"#9A9A9A"), NSFontAttributeName:kUIFont(12)} range:NSMakeRange(0, str.length)];
    [text addAttribute:NSLinkAttributeName value:@"wwwwwd://" range:[str rangeOfString:@"【我的】- 个人简介详情"]];
    self.textView.linkTextAttributes = @{NSForegroundColorAttributeName:kAppMainColor, NSFontAttributeName:kUIFont(12)};
    self.textView.attributedText = text;
    self.textView.delegate = self;
}

- (void)setupEditVoice {
    self.leftSpace.constant = 52;

    self.titleLa.text = @"更换语音提示";
    [self.leftButton setTitle:@"取消" forState:UIControlStateNormal];
    [self.rightButton setTitle:@"确定" forState:UIControlStateNormal];
    
    NSString *str = @"更换后，将清除之前已录制的语音，如需更换请确定！";
    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:str];
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing = 8;
    paragraphStyle.alignment = NSTextAlignmentCenter;
    [text addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text length])];
    [text addAttributes:@{NSForegroundColorAttributeName:kHEX(@"#9A9A9A"), NSFontAttributeName:kUIFont(12)} range:NSMakeRange(0, str.length)];
    self.textView.attributedText = text;
    self.textView.delegate = self;
    
}

- (void)setupCommonTitle:(NSString *)title content:(NSString *)content {
    self.leftSpace.constant = 34;

    self.titleLa.text = title;
    [self.leftButton setTitle:@"取消" forState:UIControlStateNormal];
    [self.rightButton setTitle:@"确定" forState:UIControlStateNormal];
    
    NSString *str = content;
    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:str];
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing = 8;
    paragraphStyle.alignment = NSTextAlignmentCenter;
    [text addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text length])];
    [text addAttributes:@{NSForegroundColorAttributeName:kHEX(@"#9A9A9A"), NSFontAttributeName:kUIFont(12)} range:NSMakeRange(0, str.length)];
    self.textView.attributedText = text;
    self.textView.delegate = self;
    
}

- (void)setupWithdrawContent:(NSString *)content {
    self.leftSpace.constant = 34;

    self.titleLa.text = @"立即提现";
    [self.leftButton setTitle:@"不提现" forState:UIControlStateNormal];
    [self.rightButton setTitle:@"提现" forState:UIControlStateNormal];
    
    NSString *str = content;
    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:str];
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing = 8;
    paragraphStyle.alignment = NSTextAlignmentCenter;
    [text addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text length])];
    [text addAttributes:@{NSForegroundColorAttributeName:kHEX(@"#9A9A9A"), NSFontAttributeName:kUIFont(12)} range:NSMakeRange(0, str.length)];
    self.textView.attributedText = text;
    self.textView.delegate = self;
}

- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange interaction:(UITextItemInteraction)interaction {
    if ([[URL scheme] isEqualToString:@"protocol"]) {
        if (self.protocolBlock) {
            self.protocolBlock();
        }
        return NO;
    }
    if ([[URL scheme] isEqualToString:@"privacy"]) {
        if (self.privacyBlock) {
            self.privacyBlock();
        }
        return NO;
    }
    return YES;
}

- (void)tipViewLeftBlock:(void (^)(void))leftBlock rightBlock:(void (^)(void))rightBlock {
    _leftBlock = leftBlock;
    _rightBlock = rightBlock;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.size = CGSizeMake(295, 177);
}

@end
